package com.example.sbbsec.fjhelper;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.support.config.FastJsonConfig;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;


public class FastJsonSerlizer<T> implements RedisSerializer<T> {
    private FastJsonConfig fastJsonConfig = new FastJsonConfig();

    @Override
    public byte[] serialize(T t) throws SerializationException {
        if (t == null) {
            return new byte[0];
        } else {
            try {
                return JSON.toJSONBytes(t, this.fastJsonConfig.getSerializeConfig(), this.fastJsonConfig.getSerializerFeatures());
            } catch (Exception var3) {
                throw new SerializationException("Could not serialize: " + var3.getMessage(), var3);
            }
        }
    }


    @Override
    public T deserialize(byte[] bytes) throws SerializationException {

            if (bytes != null && bytes.length != 0) {
                try {
                    return JSON.parseObject(bytes, FastJsonHelper.get(), this.fastJsonConfig.getFeatures());
                } catch (Exception var3) {
                    throw new SerializationException("Could not deserialize: " + var3.getMessage(), var3);
                }
            } else {
                return null;
            }
    }
}

